﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Starry.SmartAjax
{
    public abstract class BizEntity : IDisposable, IBizEntity
    {
        protected BizEntity() { }

        public abstract BizResult Execute();

        public HttpContext HttpContext { internal set; get; }

        public virtual string this[string requestName]
        {
            get { return (this.HttpContext.Request[requestName] ?? this.HttpContext.Request.Form[requestName]) ?? string.Empty; }
        }

        public virtual void Dispose()
        {
        }

        public IBizTranscation BizTranscation { set; get; }

        public virtual IBizTranscation BeginBizTranscation()
        {
            if (!(this is ITransactable))
            {
                throw new ArgumentException("该业务不支持事务", "bizEntity");
            }
            this.BizTranscation = new BizTranscation(this as ITransactable);
            return this.BizTranscation;
        }
    }
}